﻿<!DOCTYPE HTML>
<html lang="zh">
<head>
<title>MouseClick - 语法 &amp; 使用 | AutoHotkey v2</title>
<meta name="description" content="The MouseClick function clicks or holds down a mouse button, or turns the mouse wheel." />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<link href="../static/theme.css" rel="stylesheet" type="text/css" />
<script src="../static/content.js" type="text/javascript"></script>
<script type="text/javascript">$(function(){0<=window.navigator.userAgent.toLowerCase().indexOf("ucbrowser")&&CaoNiMaDeUc()})</script>
</head>
<body>

<h1>MouseClick</h1>

<p>Clicks or holds down a mouse button, or turns the mouse wheel. NOTE: The <a href="Click.htm">Click function</a> is generally more flexible and easier to use.</p>

<pre class="Syntax"><span class="func">MouseClick</span> <span class="optional">WhichButton, X, Y, ClickCount, Speed, DownOrUp, Relative</span></pre>
<h2 id="Parameters">参数</h2>
<dl>

  <dt>WhichButton</dt>
  <dd>
      <p>类型: <a href="../Concepts.htm#strings">字符串</a></p>
      <p><u>The button to click</u>: Left (default), Right, Middle (or just the first letter of each of these); or the fourth or fifth mouse button (X1 or X2). 例如: <code>MouseClick "X1"</code>. This parameter may be omitted, in which case it defaults to Left.</p>
      <p><u>Rotate the mouse wheel</u>: Specify WheelUp or WU to turn the wheel upward (away from you); specify WheelDown or WD to turn the wheel downward (toward you). Specify WheelLeft (or WL) or WheelRight (or WR) to push the wheel left or right, respectively. <em>ClickCount</em> is the number of notches to turn the wheel.</p>
      <p>To compensate automatically for cases where the user has swapped the left and right mouse buttons via the system's control panel, use the <a href="Click.htm">Click function</a> instead.</p></dd>

  <dt>X, Y</dt>
  <dd>
    <p>类型: <a href="../Concepts.htm#numbers">整数</a></p>
    <p>The x/y coordinates to which the mouse cursor is moved prior to clicking. Coordinates are relative to the active window unless <a href="CoordMode.htm">CoordMode</a> was used to change that. If omitted, the cursor's current position is used.</p>
  </dd>

  <dt>ClickCount</dt>
  <dd>
    <p>类型: <a href="../Concepts.htm#numbers">整数</a></p>
    <p>The number of times to click the mouse. If omitted, the button is clicked once.</p>
  </dd>

  <dt>Speed</dt>
  <dd>
    <p>类型: <a href="../Concepts.htm#numbers">整数</a></p>
    <p>移动鼠标的速度, 介于 0(最快) 和 100(最慢) 之间.</p>
    <p class="note"><strong>注意</strong>: 速度为 0 表示瞬时移动鼠标.</p>
    <p>如果省略, 则使用默认速度(由 <a href="SetDefaultMouseSpeed.htm">SetDefaultMouseSpeed</a> 设置, 否则为 2).</p>
    <p><em>Speed</em> is ignored for <a href="SendMode.htm">SendInput/Play modes</a>; they move the mouse instantaneously (though <a href="SetMouseDelay.htm">SetMouseDelay</a> has a mode that applies to SendPlay). To visually move the mouse more slowly -- such as a script that performs a demonstration for an audience -- use <code><a href="Send.htm#Click">SendEvent</a> "{Click 100, 200}"</code> or <code><a href="SendMode.htm">SendMode</a> "Event"</code> (optionally in conjuction with <a href="BlockInput.htm">BlockInput</a>).</p>
    <p>如果省略, 则使用默认速度(由 <a href="SetDefaultMouseSpeed.htm">SetDefaultMouseSpeed</a> 设置, 否则为 2).</p>
  </dd>

  <dt>DownOrUp</dt>
  <dd>
    <p>类型: <a href="../Concepts.htm#strings">字符串</a></p>
    <p>If omitted, each click will consist of a &quot;down&quot; event followed by an &quot;up&quot; event. To change this behavior, specify one of the following letters:</p>
    <p><strong>D:</strong> Press the mouse button down but do not release it (i.e. generate a down-event).</p>
    <p><strong>U:</strong> Release the mouse button (i.e. generate an up-event).</p>
  </dd>

  <dt>Relative</dt>
  <dd>
    <p>类型: <a href="../Concepts.htm#strings">字符串</a></p>
    <p>如果省略, 则将 X 和 Y 坐标视为绝对值. 要更改此行为, 请指定下面的字母:</p>
    <p><strong>R:</strong> The X and Y coordinates will be treated as offsets from the current mouse position. In other words, the cursor will be moved from its current position by X pixels to the right (left if negative) and Y pixels down (up if negative).</p>
  </dd>

</dl>

<h2 id="Remarks">备注</h2>
<p>这个函数使用 <a href="SendMode.htm">SendMode</a> 设置的发送方法.</p>
<p>The <a href="Click.htm">Click function</a> is recommended over MouseClick because:</p>
<ol>
  <li>It automatically compensates when the left and right mouse buttons are swapped via the control panel.</li>
  <li>It is generally easier to use.</li>
</ol>
<p>To perform a shift-click or control-click, use the <a href="Send.htm">Send</a> function before and after the operation as shown in these examples:</p>
<pre><em>; 示例 #1: </em>
Send "{Control down}"
MouseClick "left", 55, 233
Send "{Control up}"</pre>
<pre>
<em>; 示例 #2:</em>
Send "{Shift down}"
MouseClick "left", 55, 233
Send "{Shift up}"</pre>
<p>The <a href="SendMode.htm">SendPlay mode</a> is able to successfully generate mouse events in a broader variety of games than the other modes. In addition, some applications and games may have trouble tracking the mouse if it moves too quickly. The <em>speed</em> parameter or <a href="SetDefaultMouseSpeed.htm">SetDefaultMouseSpeed</a> can be used to reduce the speed (in the default <a href="SendMode.htm">SendEvent mode</a> only).</p>
<p>Some applications do not obey a <em>ClickCount</em> higher than 1 for the mouse wheel. For them, use a <a href="Loop.htm">Loop</a> such as the following:</p>
<pre>Loop 5
    MouseClick "WheelUp"</pre>
<p>可以使用 <a href="BlockInput.htm">BlockInput</a> 函数 防止用户对鼠标的任何物理操作干扰由鼠标函数产生的模拟鼠标事件. 不过, 在 <a href="SendMode.htm">SendInput/Play</a> 模式中通常不需要这样做, 因为它们会自动将用户对鼠标的物理操作延迟到发送之后.</p>
<p>There is an automatic delay after every click-down and click-up of the mouse (except for <a href="SendMode.htm">SendInput mode</a> and for turning the mouse wheel). Use <a href="SetMouseDelay.htm">SetMouseDelay</a> to change the length of the delay.</p>
<h2 id="Related">相关</h2>
<p><a href="CoordMode.htm">CoordMode</a>, <a href="SendMode.htm">SendMode</a>, <a href="SetDefaultMouseSpeed.htm">SetDefaultMouseSpeed</a>, <a href="SetMouseDelay.htm">SetMouseDelay</a>, <a href="Click.htm">Click</a>, <a href="MouseClickDrag.htm">MouseClickDrag</a>, <a href="MouseGetPos.htm">MouseGetPos</a>, 
  <a href="MouseMove.htm">MouseMove</a>, <a href="ControlClick.htm">ControlClick</a>, <a href="BlockInput.htm">BlockInput</a></p>
<h2 id="Examples">示例</h2>
<div class="ex" id="ExDoubleClick">
<p><a href="#ExDoubleClick">#1</a>: Double click at the current mouse pos:</p>
<pre>MouseClick "left"
MouseClick "left"

<em>; Same as above:</em>
MouseClick "left", , , 2</pre>
</div>

<div class="ex" id="ExMove">
<p><a href="#ExMove">#2</a>: Move to specified coordinates then right-click once:</p>
<pre>MouseClick "right", 200, 300</pre>
</div>

<div class="ex" id="ExWheel">
<p><a href="#ExWheel">#3</a>: Here are two hotkeys that simulate the turning of the mouse wheel:</p>
<pre>#up::MouseClick "WheelUp", , , 2  <em>; Turn it by two notches.</em>
#down::MouseClick "WheelDown", , , 2</pre>
</div>

</body>
</html>